package fun.yizhierha.monitor.controller;

import fun.yizhierha.common.annotation.Log;
import fun.yizhierha.common.utils.*;
import fun.yizhierha.monitor.domain.SysLog;
import fun.yizhierha.monitor.domain.vo.RetrieveSysLogVo;

import fun.yizhierha.monitor.service.SysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import java.util.Set;

/** generated by EH-Admin
* @author 二哈
* @date Fri Dec 09 20:47:12 CST 2022
**/
@Api(tags = "系统监控：操作日志")
@RestController
@RequestMapping("/api/monitor/log")
@RequiredArgsConstructor
public class SysLogController{

    private final SysLogService sysLogService;

    @ApiOperation("获取操作日志")
    @GetMapping
    @PreAuthorize("@eh.check('monitor:sysLog:list')")
    public R<PageUtils<SysLog>> list(RetrieveSysLogVo retrieveSysLogVo, Query.PageVo pageVo){
        PageUtils<SysLog> res = sysLogService.list(retrieveSysLogVo,pageVo);
        return R.<PageUtils<SysLog>>ok().setData(res);
    }

    @ApiOperation("删除操作日志")
    @Log("删除操作日志")
    @DeleteMapping
    @PreAuthorize("@eh.check('monitor:sysLog:del')")
    public R del(@RequestBody Set<Long> ids){
        sysLogService.remove(ids);
        return R.ok();
    }

    @ApiOperation("导出数据")
    @Log("导出数据")
    @GetMapping("/download")
    @PreAuthorize("@eh.check('monitor:sysLog:list')")
    public void download(HttpServletResponse response){
        sysLogService.download(response);
    }

}